package com.sskj.fca.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.fca.http.HttpConfig;
import com.sskj.fca.ui.activity.SetPayPwdActivity;

public class SetPayPwdActivityPresenter extends BasePresenter<SetPayPwdActivity> {

    /**
     * 获取短信验证码---codeType
     * 1注册 2 重置 3 安全验证 4 订单确认通知(标记付款时) 5 订单处理通知(卖给他时) 6排单成功
     *
     * @param mobile 手机号
     * @return
     */
    public void sendCode(String mobile) {
        httpService.sendCode(mobile, "3")
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.sendCodeOk();
                        } else {
                            mView.sendCodeError();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        mView.sendCodeError();
                        super.onError(response);
                    }
                });
    }

    /**
     * 设置支付密码
     *
     * @param tpwd    密码
     * @param account 用户账号
     * @param code    验证码
     * @param mobile  用户手机号
     */
    public void setPayPwd(String tpwd, String account, String code, String mobile) {
        httpService.setPayPwd(tpwd, account, code, mobile)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            ToastUtil.showShort("设置成功");
                            mView.setSuccess();
                        } else {
                            ToastUtil.showShort(httpData.msg);
                        }
                    }
                });
    }


}
